<?php
/*
 * @Author: your name
 * @Date: 2020-10-21 11:04:51
 * @LastEditTime: 2020-12-28 14:05:53
 * @LastEditors: Please set LastEditors
 * @Description: 模块伪装接口
 * @FilePath: /special/application/adminapiv3/controller/module_manage/disguise/DisguiseSetController.php
 */
namespace app\adminapiv3\controller\module_manage\disguise;

use app\adminapiv3\controller\BaseController;
use app\adminapiv3\service\module_manage\disguise\DisguiseService ;
use think\facade\Request;

class DisguiseSetController extends BaseController
{

    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-11-01 11:24:50
     */
    public function list ()
    {
        $input = Request::only(['port','protocols','status','host_id'], 'post');

        $this->validate($input, 'PortMask.listFilter');
        $PortMaskService = new DisguiseService();
        $data = $PortMaskService->list($input);

        return $this->jsonOutPut($data);
    }
    /**
     * @name: 开启
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 16:35:49
     */
    public function on ()
    {
        $input = Request::only(['middleware','sql','standard','tcp','udp'], 'post');
        $this->validate($input,'PortMask.maskOn');

        $PortMaskService = new DisguiseService();
        $PortMaskService->on($input);
        $host_id_a = $PortMaskService->getControlledFirewallHost();
        //下发命令 系统伪装信息
        $this->sendCommandToClient('disguise','disguise');
        //让客户端拉取防火墙规则如果
        $this->sendCommandToClient('netfilter','downloadRules', true, false, $host_id_a);

        return $this->jsonOutPut([],true);
    }

    /**
     * @name: 关闭
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 16:51:03
     */
    public function off ()
    {
        $input = Request::only(['host_id'], 'post');
        $this->validate($input,'PortMask.bulkHostId');
        $PortMaskService = new DisguiseService();
        $PortMaskService->off();

        //下发命令 系统伪装信息
        $this->sendCommandToClient('disguise','disguise');
        //让客户端拉取防火墙规则如果
        $host_id_a = $PortMaskService->getControlledFirewallHost();
        $this->sendCommandToClient('netfilter','downloadRules', true, false, $host_id_a);

        return $this->jsonOutPut([],true);
    }

    /**
     * @name: 设置详情
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 16:53:56
     */
    public function configInfo ()
    {
        $input = Request::only(['host_id'], 'post');
        $this->validate($input,'PortMask.oneHostId');

        $PortMaskService = new DisguiseService();
        $data = $PortMaskService->configInfo($input['host_id']);

        return $this->jsonOutPut($data);
    }

    /**
     * @name: 修改
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 16:54:18
     */
    public function configModify ()
    {
        $input = Request::only(['middleware','sql','standard','tcp','udp'], 'post');
        $this->validate($input,'PortMask.maskOn');

        $PortMaskService = new DisguiseService();
        $PortMaskService->configModify($input);

        //下发命令 系统伪装信息
        $this->sendCommandToClient('disguise','disguise');
        //让客户端拉取防火墙规则如果
        $host_id_a = $PortMaskService->getControlledFirewallHost();
        $this->sendCommandToClient('netfilter','downloadRules', true, false, $host_id_a);

        return $this->jsonOutPut([],true);
    }
}